class Solution
{
public:
    int numberOfBeams(vector<string> &bank)
    {
        int lastRowCount = 0;
        int beamCount = 0;
        for (auto &row : bank)
        {
            int deviceCount = 0;
            for (char c : row)
            {
                if (c == '1')
                {
                    ++deviceCount;
                }
            }
            if (deviceCount != 0)
            {
                beamCount += lastRowCount * deviceCount;
                lastRowCount = deviceCount;
            }
        }
        return beamCount;
    }
};